/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.IOException;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.lcdui.game.LayerManager;

/**
 *
 * @author Administrator
 */
public class MenuCanvas extends GameCanvas implements Runnable {

    //midlet
    private TheBirdMIDlet midlet;
    private Display display;
    //path
    private String pathShadow = "";
    public String pathBackground = "";
    //public static int background = 0;
    private String pathTitle = "";
    private String pathPlayOff = "";
    private String pathPlayOn = "";
    private String pathHelpOff = "";
    private String pathHelpOn = "";
    private String pathAboutOff = "";
    private String pathAboutOn = "";
    private String pathSettingsOff = "";
    private String pathSettingsOn = "";
    private String pathHighScoresOff = "";
    private String pathHighScoresOn = "";
    private String pathQuitOn = "";
    private String pathQuitBlueOn = "";
    private String pathReset = "";
    private String pathBacktoLeft = "";
    private String pathBtnResume = "";
    //private String pathBacktoRight = "";
    //private String pathBacktoUp = "";
    //path level
    private String pathGrassUnLockedOff = "";
    private String pathGrassUnLockedOn = "";
    private String pathDessertLockedOff = "";
    private String pathDessertLockedOn = "";
    private String pathDessertUnLockedOff = "";
    private String pathDessertUnLockedOn = "";
    private String pathSnowLockedOff = "";
    private String pathSnowLockedOn = "";
    private String pathSnowUnLockedOff = "";
    private String pathSnowUnLockedOn = "";
    //images        
    private Image imgTitle;
    private Image imgPlayOff;
    private Image imgPlayOn;
    private Image imgHelpOff;
    private Image imgHelpOn;
    private Image imgInfoHelp;
    private Image imgInfoSettings;
    private Image imgInfoHighScores;
    private Image imgAboutOff;
    private Image imgAboutOn;
    private Image imgInfoAbout;
    private Image imgSettingsOff;
    private Image imgSettingsOn;
    private Image imgHighScoreOff;
    private Image imgHighScoreOn;
    private Image imgQuitOn;
    private Image imgQuitBlueOn;
    private Image imgReset;
    private int btnImgMenuWidth;
    private int btnImgMenuHeight;
    private Image imgGrassUnLockedOff;
    private Image imgGrassUnLockedOn;
    private Image imgDessertLockedOff;
    private Image imgDessertLockedOn;
    private Image imgDessertUnLockedOff;
    private Image imgDessertUnLockedOn;
    private Image imgSnowLockedOff;
    private Image imgSnowLockedOn;
    private Image imgSnowUnLockedOff;
    private Image imgSnowUnLockedOn;
    private Image imgBacktoLeft;
    private Image imgTransparent;
    private Image imgBtnResume;
    //private Image imgBacktoRight;
    //private Image imgBacktoUp;
    private int btnImgLevelWidth;
    private int btnImgLevelHeight;
    //button
    private ButtonImage btnResume;
    private ButtonImage btnPlay;
    private ButtonImage btnHelp;
    private ButtonImage btnAbout;
    private ButtonImage btnInfoAbout;
    private ButtonImage btnSettings;
    private ButtonImage btnHighScores;
    private ButtonImage btnQuit;
    private ButtonImage btnQuitBlue;
    private ButtonImage btnReset;
    private ButtonImage btnGrass;
    private ButtonImage btnDessert;
    private ButtonImage btnSnow;
    private ButtonImage btnBacktoLeft;
    //ButtonImage btnBacktoRight;
    //ButtonImage btnBacktoUp;
    //font
    public static Font SMALL_PLAIN_FONT;
    public static Font SMALL_BOLD_FONT;
    public static Font LARGE_BOLD_FONT;
    //canvas property
    private int CANVAS_WIDTH = getWidth();
    private int CANVAS_HEIGHT = getHeight();
    private int bgWidth = 0;
    private int warna;
    //positions
    private int x = 0;
    private int y = 0;
    private int xBg = 0;
    private int yBg = 0;
    private int xShadow = 0;
    private int yShadow = 0;
    private int xyArea[] = new int[4];
    private int xHelp, yHelp, xPlay, yPlay, xAbout, yAbout;
    private int xSettings, ySettings, xHighScores, yHighScores;
    private int xQuit, yQuit, xGrass, yGrass, xDessert, yDessert, xSnow, ySnow;
    private int xQuitBlue, yQuitBlue;
    private int xReset, yReset;
    private int xInfoAbout, yInfoAbout;
    private int xScore, yScore;
    private int acuanMenu, acuanLevel;//, acuanAbout;
    private int jarakLevel = 0;
    //private int jarakAbout = 0;
    private int xBacktoLeft, yBacktoLeft;
    //private int xBacktoRight, yBacktoRight;
    //private int xBacktoUp, yBacktoUp;
    //animated sprite
    private AnimatedSprite spShadow;
    private static int FRAME_BLUEBIRD_WIDTH = 0;
    private static int FRAME_BLUEBIRD_HEIGHT = 0;
    public boolean running = false;
    private BackgroundScroll bgScroll;
    private LayerManager lmgr;
    //speed 
    private int speedGame = 50;
    private int speedBg = 5;
    private int speedGeser = 50;
    //boolean value
    public boolean isPaused = false;
    private boolean isGeserKeLevel = false;
    private boolean isShowAbout = false;
    private boolean isShowHelp = false;
    private boolean isShowSettings = false;
    private boolean isShowHighScores = false;
    //private boolean isGeserKeSettings = false;
    //private boolean isGeserKeHighScores = false;
    //private boolean isGeserKeHelp = false;
    //private boolean isGeserKeAbout = false;
    private boolean isGeserKeMenuFromLevel = false;
    //private boolean isGeserKeMenuFromSettings = false;
    //private boolean isGeserKeMenuFromHighScores = false;
    //private boolean isGeserKeMenuFromHelp = false;
    //private boolean isGeserKeMenuFromAbout = false;
    private boolean isGeserBackKiri = false;
    //private boolean isGeserBackAtas = false;
    //private boolean isGeserBackKanan = false;
    //private String[] nilai = new String[100];

    public MenuCanvas(TheBirdMIDlet midlet, Display display) {
        super(false);
        setFullScreenMode(true);

        this.midlet = midlet;
        this.display = display;

        CANVAS_WIDTH = getWidth();
        CANVAS_HEIGHT = getHeight();

        jarakLevel = (int) (CANVAS_WIDTH * 0.9);
        //jarakAbout = (int) (CANVAS_WIDTH * 0.9);
        warna = 0xc6eeff;

        if (CANVAS_WIDTH < CANVAS_HEIGHT) {
            //portrait
            yBg = CANVAS_HEIGHT - 240;
        } else {
            //landscape
            yBg = 0;
        }

        FRAME_BLUEBIRD_WIDTH = 23;
        FRAME_BLUEBIRD_HEIGHT = 25;
        pathShadow = "/black-shadow320.png";
        pathBackground = "/bg-snow320.png";
        pathPlayOff = "/btnPlayOff320.png";
        pathPlayOn = "/btnPlayOn320.png";
        pathHelpOff = "/btnHelpOff320.png";
        pathHelpOn = "/btnHelpOn320.png";
        pathAboutOff = "/btnAboutOff320.png";
        pathAboutOn = "/btnAboutOn320.png";
        pathSettingsOff = "/btnSettingsOff320.png";
        pathSettingsOn = "/btnSettingsOn320.png";
        pathHighScoresOff = "/btnHighScoresOff320.png";
        pathHighScoresOn = "/btnHighScoresOn320.png";
        pathBtnResume = "/btnResume320.png";

        pathQuitOn = "/close320.png";
        pathQuitBlueOn = "/closeblue320.png";
        pathReset = "/reset.png";
        pathTitle = "/titleNinjaRun320.png";
        btnImgMenuWidth = 100;
        btnImgMenuHeight = 25;
        btnImgLevelWidth = 54;
        btnImgLevelHeight = 54;
        bgWidth = 640;
        pathGrassUnLockedOff = "/grassUnlockedOff320.png";
        pathGrassUnLockedOn = "/grassUnlockedOn320.png";
        pathDessertLockedOff = "/dessertLockedOff320.png";
        pathDessertLockedOn = "/dessertLockedOn320.png";
        pathDessertUnLockedOff = "/dessertUnlockedOff320.png";
        pathDessertUnLockedOn = "/dessertUnlockedOn320.png";
        pathSnowLockedOff = "/snowLockedOff320.png";
        pathSnowLockedOn = "/snowLockedOn320.png";
        pathSnowUnLockedOff = "/snowUnockedOff320.png";
        pathSnowUnLockedOn = "/snowUnockedOn320.png";
        pathBacktoLeft = "/btnBacktoLeft.png";
        //pathBacktoRight = "/btnBacktoRight.png";
//        /pathBacktoUp = "/btnBacktoUp.png";


        try {
            bgScroll = new BackgroundScroll(Image.createImage(pathBackground));
            bgScroll.setRefPixelPosition(xBg, yBg);
            //animated sprite
            spShadow = new AnimatedSprite(Image.createImage(pathShadow),
                    FRAME_BLUEBIRD_WIDTH, FRAME_BLUEBIRD_HEIGHT);
            spShadow.defineReferencePixel(FRAME_BLUEBIRD_WIDTH / 2, FRAME_BLUEBIRD_HEIGHT / 2);

            lmgr = new LayerManager();
            lmgr.append(spShadow);
            lmgr.append(bgScroll);
        } catch (IOException ex) {
        }

        try {
            imgTitle = Image.createImage(pathTitle);
            imgBacktoLeft = Image.createImage(pathBacktoLeft);
            //imgBacktoRight = Image.createImage(pathBacktoRight);
            //imgBacktoUp = Image.createImage(pathBacktoUp);

            imgPlayOff = Image.createImage(pathPlayOff);
            imgPlayOn = Image.createImage(pathPlayOn);
            imgHelpOff = Image.createImage(pathHelpOff);
            imgHelpOn = Image.createImage(pathHelpOn);
            imgAboutOff = Image.createImage(pathAboutOff);
            imgAboutOn = Image.createImage(pathAboutOn);
            imgInfoAbout = Image.createImage("/about.png");
            imgInfoHelp = Image.createImage("/help.png");
            imgInfoSettings = Image.createImage("/settings.png");
            imgInfoHighScores = Image.createImage("/highscores.png");
            imgTransparent = Image.createImage("/transparent.png");
            imgBtnResume = Image.createImage(pathBtnResume);

            imgSettingsOff = Image.createImage(pathSettingsOff);
            imgSettingsOn = Image.createImage(pathSettingsOn);

            imgHighScoreOff = Image.createImage(pathHighScoresOff);
            imgHighScoreOn = Image.createImage(pathHighScoresOn);

            imgQuitOn = Image.createImage(pathQuitOn);
            imgQuitBlueOn = Image.createImage(pathQuitBlueOn);
            imgReset = Image.createImage(pathReset);

            imgGrassUnLockedOff = Image.createImage(pathGrassUnLockedOff);
            imgGrassUnLockedOn = Image.createImage(pathGrassUnLockedOn);
            imgDessertLockedOff = Image.createImage(pathDessertLockedOff);
            imgDessertLockedOn = Image.createImage(pathDessertLockedOn);
            imgDessertUnLockedOff = Image.createImage(pathDessertUnLockedOff);
            imgDessertUnLockedOn = Image.createImage(pathDessertUnLockedOn);
            imgSnowLockedOff = Image.createImage(pathSnowLockedOff);
            imgSnowLockedOn = Image.createImage(pathSnowLockedOn);
            imgSnowUnLockedOff = Image.createImage(pathSnowUnLockedOff);
            imgSnowUnLockedOn = Image.createImage(pathSnowUnLockedOn);

        } catch (IOException ex) {
        }

        SMALL_PLAIN_FONT = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN, Font.SIZE_SMALL);
        SMALL_BOLD_FONT = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_SMALL);
        LARGE_BOLD_FONT = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_LARGE);


        xHelp = (int) (getWidth() * 0.25) - (btnImgMenuWidth / 2);
        yHelp = (int) (getHeight() * 0.25) - (btnImgMenuHeight / 2);
        xPlay = (int) (getWidth() * 0.5) - (btnImgMenuWidth / 2);
        yPlay = (int) (getHeight() * 0.5) - (btnImgMenuHeight / 2);
        xAbout = (int) (getWidth() * 0.75) - (btnImgMenuWidth / 2);
        yAbout = (int) (getHeight() * 0.75) - (btnImgMenuHeight / 2);

        xSettings = (int) (getWidth() * 0.25) - (btnImgMenuWidth / 2);
        ySettings = (int) (getHeight() * 0.75) - (btnImgMenuHeight / 2);
        xHighScores = (int) (getWidth() * 0.75) - (btnImgMenuWidth / 2);
        yHighScores = (int) (getHeight() * 0.25) - (btnImgMenuHeight / 2);

        xQuit = (int) getWidth() - imgQuitOn.getWidth();
        yQuit = 0;
        xQuitBlue = (int) (getWidth() * 0.72);
        yQuitBlue = (int) (getHeight() * 0.32);
        xReset = (int) (getWidth() * 0.35);
        yReset = (int) (getHeight() * 0.80);

        acuanMenu = xHelp;

        xGrass = (int) (getWidth() * 0.4) - (btnImgLevelWidth / 2) + jarakLevel;
        yGrass = (int) (getHeight() * 0.3) - (btnImgLevelHeight / 2);
        xDessert = (int) (getWidth() * 0.65) - (btnImgLevelWidth / 2) + jarakLevel;
        yDessert = (int) (getHeight() * 0.5) - (btnImgLevelHeight / 2);
        xSnow = (int) (getWidth() * 0.85) - (btnImgLevelWidth / 2) + jarakLevel;
        ySnow = (int) (getHeight() * 0.75) - (btnImgLevelHeight / 2);
        acuanLevel = (int) (getWidth() * 0.3) - (btnImgLevelWidth / 2);

        xInfoAbout = (int) (getWidth() * 0.2);// - jarakAbout;
        yInfoAbout = (int) (getHeight() * 0.3);
        xScore = (int) (getWidth() * 0.25);// - jarakAbout;
        yScore = (int) (getHeight() * 0.44);
        //acuanAbout = (int) (getWidth() * 0.3);

        xBacktoLeft = 0;//getWidth() - imgMineIdOff.getWidth();
        yBacktoLeft = getHeight() - imgBacktoLeft.getHeight();

        int xResume = getWidth() / 2 - (imgBtnResume.getWidth() / 2);
        int yResume = getHeight() / 2 - (imgBtnResume.getHeight() / 2);
        xyArea[0] = xResume; //x1
        xyArea[1] = xResume + imgBtnResume.getWidth(); //x2
        xyArea[2] = yResume; //y1
        xyArea[3] = yResume + imgBtnResume.getHeight(); //y2
        btnResume = new ButtonImage("resume", imgBtnResume, imgBtnResume,
                imgBtnResume, xResume,
                yResume, xyArea, Graphics.TOP | Graphics.LEFT);

        xyArea[0] = yHelp; //x1
        xyArea[1] = yHelp + imgHelpOff.getWidth(); //x2
        xyArea[2] = xHelp; //y1
        xyArea[3] = xHelp + imgHelpOff.getHeight(); //y2
        btnHelp = new ButtonImage("help", imgHelpOff, imgHelpOn,
                imgHelpOff, xHelp,
                yHelp, xyArea, Graphics.TOP | Graphics.LEFT);

        xyArea[0] = yPlay; //x1
        xyArea[1] = yPlay + imgPlayOff.getWidth(); //x2
        xyArea[2] = xPlay; //y1
        xyArea[3] = xPlay + imgPlayOff.getHeight(); //y2
        btnPlay = new ButtonImage("play", imgPlayOff, imgPlayOn,
                imgPlayOff, xPlay,
                yPlay, xyArea, Graphics.TOP | Graphics.LEFT);

        xyArea[0] = yAbout; //x1
        xyArea[1] = yAbout + btnImgMenuWidth; //x2
        xyArea[2] = xAbout; //y1
        xyArea[3] = xAbout + btnImgMenuHeight; //y2
        btnAbout = new ButtonImage("about", imgAboutOff, imgAboutOn,
                imgAboutOff, xAbout,
                yAbout, xyArea, Graphics.TOP | Graphics.LEFT);

        xyArea[0] = yInfoAbout; //x1
        xyArea[1] = yInfoAbout + imgInfoAbout.getWidth(); //x2
        xyArea[2] = xInfoAbout; //y1
        xyArea[3] = xInfoAbout + imgInfoAbout.getHeight(); //y2
        btnInfoAbout = new ButtonImage("infoabout", imgInfoAbout, imgInfoAbout,
                imgInfoAbout, xInfoAbout,
                yInfoAbout, xyArea, Graphics.TOP | Graphics.LEFT);

        xyArea[0] = ySettings; //x1
        xyArea[1] = ySettings + btnImgMenuWidth; //x2
        xyArea[2] = xSettings; //y1
        xyArea[3] = xSettings + btnImgMenuHeight; //y2
        btnSettings = new ButtonImage("settings", imgSettingsOff, imgSettingsOn,
                imgSettingsOff, xSettings,
                ySettings, xyArea, Graphics.TOP | Graphics.LEFT);

        xyArea[0] = yHighScores; //x1
        xyArea[1] = yHighScores + btnImgMenuWidth; //x2
        xyArea[2] = xHighScores; //y1
        xyArea[3] = xHighScores + btnImgMenuHeight; //y2
        btnHighScores = new ButtonImage("highscores", imgHighScoreOff, imgHighScoreOn,
                imgHighScoreOff, xHighScores,
                yHighScores, xyArea, Graphics.TOP | Graphics.LEFT);

        xyArea[0] = yQuit; //x1
        xyArea[1] = yQuit + imgQuitOn.getWidth(); //x2
        xyArea[2] = xQuit; //y1
        xyArea[3] = xQuit + imgQuitOn.getHeight(); //y2
        btnQuit = new ButtonImage("quit", imgQuitOn, imgQuitOn,
                imgQuitOn, xQuit,
                yQuit, xyArea, Graphics.TOP | Graphics.LEFT);

        xyArea[0] = yQuitBlue; //x1
        xyArea[1] = yQuitBlue + imgQuitBlueOn.getWidth(); //x2
        xyArea[2] = xQuitBlue; //y1
        xyArea[3] = xQuitBlue + imgQuitBlueOn.getHeight(); //y2
        btnQuitBlue = new ButtonImage("quitblue", imgQuitBlueOn, imgQuitBlueOn,
                imgQuitBlueOn, xQuitBlue,
                yQuitBlue, xyArea, Graphics.TOP | Graphics.LEFT);

        xyArea[0] = yReset; //x1
        xyArea[1] = yReset + imgReset.getWidth(); //x2
        xyArea[2] = xReset; //y1
        xyArea[3] = xReset + imgReset.getHeight(); //y2
        btnReset = new ButtonImage("reset", imgReset, imgReset,
                imgReset, xReset,
                yReset, xyArea, Graphics.TOP | Graphics.LEFT);

        btnPlay.setIsPressed(true);

        xyArea[0] = yGrass; //x1
        xyArea[1] = yGrass + btnImgLevelWidth; //x2
        xyArea[2] = xGrass; //y1
        xyArea[3] = xGrass + btnImgMenuHeight; //y2
        btnGrass = new ButtonImage("grass", imgGrassUnLockedOff, imgGrassUnLockedOn,
                imgGrassUnLockedOff, xGrass,
                yGrass, xyArea, Graphics.TOP | Graphics.LEFT);

        xyArea[0] = yDessert; //x1
        xyArea[1] = yDessert + btnImgLevelWidth; //x2
        xyArea[2] = xDessert; //y1
        xyArea[3] = xDessert + btnImgMenuHeight; //y2
        btnDessert = new ButtonImage("dessert", imgDessertLockedOff, imgDessertLockedOn,
                imgDessertLockedOff, xDessert,
                yDessert, xyArea, Graphics.TOP | Graphics.LEFT);

        xyArea[0] = ySnow; //x1
        xyArea[1] = ySnow + btnImgLevelWidth; //x2
        xyArea[2] = xSnow; //y1
        xyArea[3] = xSnow + btnImgMenuHeight; //y2
        btnSnow = new ButtonImage("snow", imgSnowLockedOff, imgSnowLockedOn,
                imgSnowLockedOff, xSnow,
                ySnow, xyArea, Graphics.TOP | Graphics.LEFT);

        xyArea[0] = yBacktoLeft; //x1
        xyArea[1] = yBacktoLeft + imgBacktoLeft.getWidth(); //x2
        xyArea[2] = xBacktoLeft; //y1
        xyArea[3] = xBacktoLeft + imgBacktoLeft.getHeight(); //y2
        btnBacktoLeft = new ButtonImage("backtoleft", imgBacktoLeft, imgBacktoLeft,
                imgBacktoLeft, xBacktoLeft,
                yBacktoLeft, xyArea, Graphics.TOP | Graphics.LEFT);

        /*
        xyArea[0] = yBacktoRight; //x1
        xyArea[1] = yBacktoRight + imgBacktoRight.getWidth(); //x2
        xyArea[2] = xBacktoRight; //y1
        xyArea[3] = xBacktoRight + imgBacktoRight.getHeight(); //y2
        btnBacktoRight = new ButtonImage("backtoright", imgBacktoRight, imgBacktoRight,
        imgBacktoRight, xBacktoRight,
        yBacktoRight, xyArea, Graphics.TOP | Graphics.LEFT);

        xyArea[0] = yBacktoUp; //x1
        xyArea[1] = yBacktoUp + imgBacktoUp.getWidth(); //x2
        xyArea[2] = xBacktoUp; //y1
        xyArea[3] = xBacktoUp + imgBacktoUp.getHeight(); //y2
        btnBacktoUp = new ButtonImage("backtoup", imgBacktoUp, imgBacktoUp,
        imgBacktoUp, xBacktoUp,
        yBacktoUp, xyArea, Graphics.TOP | Graphics.LEFT);
         * 
         */
        xShadow = (int) ((CANVAS_WIDTH * 0.1));
        yShadow = (int) ((CANVAS_HEIGHT * 0.65));
        btnGrass.setIsPressed(true);

        spShadow.setRefPixelPosition(xShadow, yShadow);

        //System.out.println(CANVAS_WIDTH + "x" + CANVAS_HEIGHT);

    }
    //start thread

    public void start() {
        running = true;
        Thread t = new Thread(this);
        t.start();
    }

    //game loop
    public void run() {
        Graphics g = getGraphics();
        while (running) {
            // look for keypress
            //checkForKeys();
            //checkForCollision();            

            if (isGeserKeLevel) {
                if (xGrass < acuanLevel) {
                    isGeserKeLevel = false;
                    isGeserBackKiri = true;
                }
            }


            //System.out.println(xInfoAbout +"  ,  " + acuanAbout);
            /*
            if (isGeserKeAbout) {
            if (xInfoAbout > acuanAbout) {
            isGeserBackKanan = true;
            isGeserKeAbout = false;
            }
            }
             * 
             */

            if (isGeserKeMenuFromLevel) {
                //System.out.println("xhelp" + xHelp);
                if (xHelp > acuanMenu) {
                    isGeserKeMenuFromLevel = false;

                    xHelp = xHelp - speedGeser;
                    xPlay = xPlay - speedGeser;
                    xAbout = xAbout - speedGeser;
                    xSettings = xSettings - speedGeser;
                    xHighScores = xHighScores - speedGeser;


                    xGrass = xGrass - speedGeser;
                    xDessert = xDessert - speedGeser;
                    xSnow = xSnow - speedGeser;

                    btnHelp.setPositionXY(xHelp, yHelp, Graphics.TOP | Graphics.LEFT);
                    btnPlay.setPositionXY(xPlay, yPlay, Graphics.TOP | Graphics.LEFT);
                    btnAbout.setPositionXY(xAbout, yAbout, Graphics.TOP | Graphics.LEFT);
                    btnSettings.setPositionXY(xSettings, ySettings, Graphics.TOP | Graphics.LEFT);
                    btnHighScores.setPositionXY(xHighScores, yHighScores, Graphics.TOP | Graphics.LEFT);

                    btnGrass.setPositionXY(xGrass, yGrass, Graphics.TOP | Graphics.LEFT);
                    btnDessert.setPositionXY(xDessert, yDessert, Graphics.TOP | Graphics.LEFT);
                    btnSnow.setPositionXY(xSnow, ySnow, Graphics.TOP | Graphics.LEFT);
                }
            }

            /*
            if (isGeserKeMenuFromAbout) {
            if (xInfoAbout < acuanAbout) {
            isGeserKeMenuFromAbout = false;
            xHelp = xHelp - speedGeser;
            xPlay = xPlay - speedGeser;
            xAbout = xAbout - speedGeser;
            xSettings = xSettings - speedGeser;
            xHighScores = xHighScores - speedGeser;

            xInfoAbout = xInfoAbout - speedGeser;

            btnHelp.setPositionXY(xHelp, yHelp, Graphics.TOP | Graphics.LEFT);
            btnPlay.setPositionXY(xPlay, yPlay, Graphics.TOP | Graphics.LEFT);
            btnAbout.setPositionXY(xAbout, yAbout, Graphics.TOP | Graphics.LEFT);
            btnSettings.setPositionXY(xSettings, ySettings, Graphics.TOP | Graphics.LEFT);
            btnHighScores.setPositionXY(xHighScores, yHighScores, Graphics.TOP | Graphics.LEFT);

            }
            }
             * 
             */

            //System.out.println("xHelp : " + xHelp
            //        + " acuanMenu : " + acuanMenu);

            drawDisplay(g);

            //System.out.println(spShuriken.getX());
            try {
                Thread.sleep(speedGame);
            } catch (InterruptedException ie) {
            }
        }
    }

    public void stop() {
        running = false;
    }

    /*
    protected void sizeChanged(int i, int i1) {
    super.sizeChanged(i, i1);
    //System.out.println("Oit!");
    System.out.println(getWidth() + "x" +getHeight());
    }
     *
     */
    protected void drawDisplay(Graphics g) {
        //System.out.println(isGeserBackKanan);

        g.setColor(warna);
        g.fillRect(0, 0, getWidth(), getHeight());

        if (xBg == -bgWidth) {
            xBg = 0;
        } else {
            xBg = xBg - speedBg;
        }
        bgScroll.setPosition(xBg, yBg);
        spShadow.nextFrame();
        lmgr.paint(g, 0, 0);

        g.drawImage(imgTitle, CANVAS_WIDTH / 2 - (imgTitle.getWidth() / 2), 0, Graphics.TOP | Graphics.LEFT);

        //System.out.println(xInfoAbout + " , " + yInfoAbout);


        //paint disini
        //sampai sini        

        //flush off-screen buffer to display        
        if (isGeserKeLevel) {
            xHelp = xHelp - speedGeser;
            xPlay = xPlay - speedGeser;
            xAbout = xAbout - speedGeser;
            xSettings = xSettings - speedGeser;
            xHighScores = xHighScores - speedGeser;

            xGrass = xGrass - speedGeser;
            xDessert = xDessert - speedGeser;
            xSnow = xSnow - speedGeser;

            btnHelp.setPositionXY(xHelp, yHelp, Graphics.TOP | Graphics.LEFT);
            btnPlay.setPositionXY(xPlay, yPlay, Graphics.TOP | Graphics.LEFT);
            btnAbout.setPositionXY(xAbout, yAbout, Graphics.TOP | Graphics.LEFT);
            btnSettings.setPositionXY(xSettings, ySettings, Graphics.TOP | Graphics.LEFT);
            btnHighScores.setPositionXY(xHighScores, yHighScores, Graphics.TOP | Graphics.LEFT);

            btnGrass.setPositionXY(xGrass, yGrass, Graphics.TOP | Graphics.LEFT);
            btnDessert.setPositionXY(xDessert, yDessert, Graphics.TOP | Graphics.LEFT);
            btnSnow.setPositionXY(xSnow, ySnow, Graphics.TOP | Graphics.LEFT);
        }
        if (isGeserBackKiri) {
            //System.out.println("backtoKiri on");
            btnBacktoLeft.paint(g);
        }
        if (isGeserKeMenuFromLevel) {
            xHelp = xHelp + speedGeser;
            xPlay = xPlay + speedGeser;
            xAbout = xAbout + speedGeser;
            xSettings = xSettings + speedGeser;
            xHighScores = xHighScores + speedGeser;

            xGrass = xGrass + speedGeser;
            xDessert = xDessert + speedGeser;
            xSnow = xSnow + speedGeser;

            btnHelp.setPositionXY(xHelp, yHelp, Graphics.TOP | Graphics.LEFT);
            btnPlay.setPositionXY(xPlay, yPlay, Graphics.TOP | Graphics.LEFT);
            btnAbout.setPositionXY(xAbout, yAbout, Graphics.TOP | Graphics.LEFT);
            btnSettings.setPositionXY(xSettings, ySettings, Graphics.TOP | Graphics.LEFT);
            btnHighScores.setPositionXY(xHighScores, yHighScores, Graphics.TOP | Graphics.LEFT);

            btnGrass.setPositionXY(xGrass, yGrass, Graphics.TOP | Graphics.LEFT);
            btnDessert.setPositionXY(xDessert, yDessert, Graphics.TOP | Graphics.LEFT);
            btnSnow.setPositionXY(xSnow, ySnow, Graphics.TOP | Graphics.LEFT);
        }

        /*
        if (isGeserKeAbout) {
        xHelp = xHelp + speedGeser;
        xPlay = xPlay + speedGeser;
        xAbout = xAbout + speedGeser;
        xSettings = xSettings + speedGeser;
        xHighScores = xHighScores + speedGeser;

        xInfoAbout = xInfoAbout + speedGeser;

        btnHelp.setPositionXY(xHelp, yHelp, Graphics.TOP | Graphics.LEFT);
        btnPlay.setPositionXY(xPlay, yPlay, Graphics.TOP | Graphics.LEFT);
        btnAbout.setPositionXY(xAbout, yAbout, Graphics.TOP | Graphics.LEFT);
        btnSettings.setPositionXY(xSettings, ySettings, Graphics.TOP | Graphics.LEFT);
        btnHighScores.setPositionXY(xHighScores, yHighScores, Graphics.TOP | Graphics.LEFT);
        }
        if (isGeserBackKanan) {
        //System.out.println("backto Kanan on");
        btnBacktoRight.paint(g);
        }
        if (isGeserKeMenuFromAbout) {
        xHelp = xHelp - speedGeser;
        xPlay = xPlay - speedGeser;
        xAbout = xAbout - speedGeser;
        xSettings = xSettings - speedGeser;
        xHighScores = xHighScores - speedGeser;

        xInfoAbout = xInfoAbout - speedGeser;

        btnHelp.setPositionXY(xHelp, yHelp, Graphics.TOP | Graphics.LEFT);
        btnPlay.setPositionXY(xPlay, yPlay, Graphics.TOP | Graphics.LEFT);
        btnAbout.setPositionXY(xAbout, yAbout, Graphics.TOP | Graphics.LEFT);
        btnSettings.setPositionXY(xSettings, ySettings, Graphics.TOP | Graphics.LEFT);
        btnHighScores.setPositionXY(xHighScores, yHighScores, Graphics.TOP | Graphics.LEFT);
        }
         * 
         */

        btnPlay.paint(g);
        btnAbout.paint(g);
        btnSettings.paint(g);
        btnHighScores.paint(g);
        btnHelp.paint(g);
        btnQuit.paint(g);

        btnGrass.paint(g);
        btnDessert.paint(g);
        btnSnow.paint(g);


        if (isShowAbout) {
            drawTransparent(g);
            g.drawImage(imgInfoAbout, xInfoAbout, yInfoAbout, Graphics.TOP | Graphics.LEFT);
            btnQuitBlue.paint(g);
        }
        if (isShowHelp) {
            drawTransparent(g);
            g.drawImage(imgInfoHelp, xInfoAbout, yInfoAbout, Graphics.TOP | Graphics.LEFT);
            btnQuitBlue.paint(g);
        }
        if (isShowHighScores) {
            drawTransparent(g);
            g.drawImage(imgInfoHighScores, xInfoAbout, yInfoAbout, Graphics.TOP | Graphics.LEFT);
            g.setColor(0x0000ff);
            for (int i = 0; i < 5; i++) {
                //g.drawString(i + 1 + ". " + formatNilai(nilai[i]), xScore, yScore + (i * 20), Graphics.TOP | Graphics.LEFT);
                g.drawString(i + 1 + ". " + TheBirdMIDlet.limaNilai[i], xScore, yScore + (i * 20), Graphics.TOP | Graphics.LEFT);
            }

            btnQuitBlue.paint(g);
            btnReset.paint(g);
        }
        if (isShowSettings) {
            drawTransparent(g);
            g.drawImage(imgInfoSettings, xInfoAbout, yInfoAbout, Graphics.TOP | Graphics.LEFT);
            btnQuitBlue.paint(g);
        }

        //g.setColor(0x0000ff);
        //g.drawString("for test only : " + getWidth() + "x" + getHeight(), 0, 10, Graphics.TOP | Graphics.LEFT);

        flushGraphics();
    }

    private void drawTransparent(Graphics g) {
        g.drawImage(imgTransparent, 0, 0, Graphics.TOP | Graphics.LEFT);
    }

    /*
    private void checkForKeys() {
    int keyState = getKeyStates();

    if ((keyState & FIRE_PRESSED) != 0) {
    //isAttack = true;
    keyPressed(-5);
    //System.out.println(getKeyStates());
    } else if ((keyState & LEFT_PRESSED) != 0) {
    keyPressed(-3);
    //System.out.println(getKeyStates());
    } else if ((keyState & RIGHT_PRESSED) != 0) {
    keyPressed(-4);
    //System.out.println(getKeyStates());
    } else if ((keyState & UP_PRESSED) != 0) {
    keyPressed(-1);
    //System.out.println(getKeyStates());
    } else if ((keyState & DOWN_PRESSED) != 0) {
    keyPressed(-2);
    //System.out.println(getKeyStates());
    } else if ((keyState & GAME_A_PRESSED) != 0) {
    //System.out.println("A!!!");
    } else if ((keyState & GAME_B_PRESSED) != 0) {
    //System.out.println("B!!!");
    } else if ((keyState & GAME_C_PRESSED) != 0) {
    //System.out.println("C!!!");
    } else if ((keyState & GAME_D_PRESSED) != 0) {
    //System.out.println("D!!!");
    }
    }
     * 
     */
    protected void keyPressed(int keyCode) {
        if (keyCode == -5) {
            if (isShowAbout) {
                isShowAbout = false;
            } else if (isShowHelp) {
                isShowHelp = false;
            } else if (isShowHighScores) {
                isShowHighScores = false;
            } else if (isShowSettings) {
                isShowSettings = false;
            } else {
                if (btnQuit.isIsPressed()) {
                    midlet.exit();
                }
                if (isGeserBackKiri) {
                    if (btnGrass.isIsPressed()) {
                        midlet.showGrassCanvas();
                    } else if (btnDessert.isIsPressed()) {
                        midlet.showDessertCanvas();
                    } else if (btnSnow.isIsPressed()) {
                        //midlet.showSnowCanvas();
                    }
                } else {
                    if (btnPlay.isIsPressed()) {
                        isGeserKeLevel = true;
                    } else if (btnAbout.isIsPressed()) {
                        //midlet.showAboutCanvas();
                        //isGeserKeAbout = true;
                        isShowAbout = true;
                    } else if (btnHelp.isIsPressed()) {
                        //midlet.showHelpCanvas();
                        //isGeserKeHelp = true;
                        isShowHelp = true;
                    } else if (btnSettings.isIsPressed()) {
                        //midlet.showHelpCanvas();
                        //isGeserKeSettings = true;
                        isShowSettings = true;
                    } else if (btnHighScores.isIsPressed()) {
                        //midlet.showHelpCanvas();
                        //isGeserKeHighScores = true;
                        //isShowHighScores = true;
                        midlet.showHighScores(0, false);
                    }
                }
            }

        } else if (keyCode == -2 || keyCode == -4) {
            //pencet bawah /kanan

            if (btnHelp.isIsPressed()) {
                btnHelp.setIsNothing(true);
                btnHelp.setIsPressed(false);
                btnHighScores.setIsPressed(true);
            } else if (btnHighScores.isIsPressed()) {
                btnHighScores.setIsNothing(true);
                btnHighScores.setIsPressed(false);
                btnPlay.setIsPressed(true);
            } else if (btnPlay.isIsPressed()) {
                btnPlay.setIsNothing(true);
                btnPlay.setIsPressed(false);
                btnSettings.setIsPressed(true);
            } else if (btnSettings.isIsPressed()) {
                btnSettings.setIsNothing(true);
                btnSettings.setIsPressed(false);
                btnAbout.setIsPressed(true);
            } else if (btnAbout.isIsPressed()) {
                btnAbout.setIsNothing(true);
                btnAbout.setIsPressed(false);
                btnHelp.setIsPressed(true);
            }

            //menu
            if (btnGrass.isIsPressed()) {
                btnGrass.setIsNothing(true);
                btnGrass.setIsPressed(false);
                btnDessert.setIsPressed(true);
                //System.out.println("grass oi");
            } else if (btnDessert.isIsPressed()) {
                btnDessert.setIsNothing(true);
                btnDessert.setIsPressed(false);
                btnSnow.setIsPressed(true);
                //System.out.println("dessert oi");
            } else if (btnSnow.isIsPressed()) {
                btnSnow.setIsNothing(true);
                btnSnow.setIsPressed(false);
                btnGrass.setIsPressed(true);
                //System.out.println("snow oi");
            }
        } else if (keyCode == -1 || keyCode == -3) {
            //pencet atas / kiri

            if (btnHelp.isIsPressed()) {
                btnHelp.setIsNothing(true);
                btnHelp.setIsPressed(false);
                btnAbout.setIsPressed(true);
            } else if (btnHighScores.isIsPressed()) {
                btnHighScores.setIsNothing(true);
                btnHighScores.setIsPressed(false);
                btnHelp.setIsPressed(true);
            } else if (btnPlay.isIsPressed()) {
                btnPlay.setIsNothing(true);
                btnPlay.setIsPressed(false);
                btnHighScores.setIsPressed(true);
            } else if (btnSettings.isIsPressed()) {
                btnSettings.setIsNothing(true);
                btnSettings.setIsPressed(false);
                btnPlay.setIsPressed(true);
            } else if (btnAbout.isIsPressed()) {
                btnAbout.setIsNothing(true);
                btnAbout.setIsPressed(false);
                btnSettings.setIsPressed(true);
            }

            if (btnGrass.isIsPressed()) {
                btnGrass.setIsNothing(true);
                btnGrass.setIsPressed(false);
                btnSnow.setIsPressed(true);
            } else if (btnDessert.isIsPressed()) {
                btnDessert.setIsNothing(true);
                btnDessert.setIsPressed(false);
                btnGrass.setIsPressed(true);
            } else if (btnSnow.isIsPressed()) {
                btnSnow.setIsNothing(true);
                btnSnow.setIsPressed(false);
                btnDessert.setIsPressed(true);
            }
        } else if (keyCode == -7) {
            midlet.exit();
        } else if (keyCode == -6) {
            if (isGeserBackKiri) {
                isGeserBackKiri = false;
                isGeserKeMenuFromLevel = true;
            }

            /*
            if (isGeserBackKanan) {
            isGeserBackKanan = false;
            isGeserKeMenuFromAbout = true;
            }
             * 
             */
        }
        repaint();
    }

    protected void pointerPressed(int x, int y) {
        //recognizer = new GestureRecognizer(x, y);
        this.x = x;
        this.y = y;

        if (isPaused) {
        } else {
            if (isShowAbout) {
                if (x > btnQuitBlue.xImage
                        && x < (btnQuitBlue.xImage + btnQuitBlue.imageWidth)
                        && y > btnQuitBlue.yImage
                        && y < (btnQuitBlue.yImage + btnQuitBlue.imageHeight)) {
                    isShowAbout = false;
                }
            } else if (isShowHelp) {
                if (x > btnQuitBlue.xImage
                        && x < (btnQuitBlue.xImage + btnQuitBlue.imageWidth)
                        && y > btnQuitBlue.yImage
                        && y < (btnQuitBlue.yImage + btnQuitBlue.imageHeight)) {
                    isShowHelp = false;
                }
            } else if (isShowHighScores) {
                if (x > btnQuitBlue.xImage
                        && x < (btnQuitBlue.xImage + btnQuitBlue.imageWidth)
                        && y > btnQuitBlue.yImage
                        && y < (btnQuitBlue.yImage + btnQuitBlue.imageHeight)) {
                    isShowHighScores = false;
                    //System.out.println("yeah 11111");
                }

                if (x > btnReset.xImage
                        && x < (btnReset.xImage + btnReset.imageWidth)
                        && y > btnReset.yImage
                        && y < (btnReset.yImage + btnReset.imageHeight)) {
                    System.out.println("reset sayang :*");
                }
            } else if (isShowSettings) {
                if (x > btnQuitBlue.xImage
                        && x < (btnQuitBlue.xImage + btnQuitBlue.imageWidth)
                        && y > btnQuitBlue.yImage
                        && y < (btnQuitBlue.yImage + btnQuitBlue.imageHeight)) {
                    isShowSettings = false;
                }
            } else {
                if (x > btnQuit.xImage
                        && x < (btnQuit.xImage + btnQuit.imageWidth)
                        && y > btnQuit.yImage
                        && y < (btnQuit.yImage + btnQuit.imageHeight)) {
                    keyPressed(-7);
                }

                //show = false;
                if (x > btnHelp.xImage
                        && x < (btnHelp.xImage + btnHelp.imageWidth)
                        && y > btnHelp.yImage
                        && y < (btnHelp.yImage + btnHelp.imageHeight)) {
                    btnHelp.pointerPressed(x, y);
                    repaint();
                } else if (x > btnAbout.xImage
                        && x < (btnAbout.xImage + btnAbout.imageWidth)
                        && y > btnAbout.yImage
                        && y < (btnAbout.yImage + btnAbout.imageHeight)) {
                    btnAbout.pointerPressed(x, y);
                    repaint();
                } else if (x > btnSettings.xImage
                        && x < (btnSettings.xImage + btnSettings.imageWidth)
                        && y > btnSettings.yImage
                        && y < (btnSettings.yImage + btnSettings.imageHeight)) {
                    btnSettings.pointerPressed(x, y);
                    repaint();
                } else if (x > btnHighScores.xImage
                        && x < (btnHighScores.xImage + btnHighScores.imageWidth)
                        && y > btnHighScores.yImage
                        && y < (btnHighScores.yImage + btnHighScores.imageHeight)) {
                    btnHighScores.pointerPressed(x, y);
                    repaint();
                } else if (x > btnPlay.xImage
                        && x < (btnPlay.xImage + btnPlay.imageWidth)
                        && y > btnPlay.yImage
                        && y < (btnPlay.yImage + btnPlay.imageHeight)) {
                    btnPlay.pointerPressed(x, y);
                    repaint();
                }

                if (isGeserBackKiri) {
                    if (x > btnBacktoLeft.xImage
                            && x < (btnBacktoLeft.xImage + btnBacktoLeft.imageWidth)
                            && y > btnBacktoLeft.yImage
                            && y < (btnBacktoLeft.yImage + btnBacktoLeft.imageHeight)) {
                        isGeserBackKiri = false;
                        isGeserKeMenuFromLevel = true;
                    }
                }
            }
        }
    }

    protected void pointerReleased(int x, int y) {
        //recognizer.endGesture(x, y);
        this.x = x;
        this.y = y;
        //show = true;

        if (isPaused) {
            if (x > btnResume.xImage
                    && x < (btnResume.xImage + btnResume.imageWidth)
                    && y > btnResume.yImage
                    && y < (btnResume.yImage + btnResume.imageHeight)) {
                isPaused = false;
                start();
                repaint();
            }
        } else {
            if (isShowAbout) {
            } else if (isShowHelp) {
            } else if (isShowHighScores) {
                if (x > btnQuitBlue.xImage
                        && x < (btnQuitBlue.xImage + btnQuitBlue.imageWidth)
                        && y > btnQuitBlue.yImage
                        && y < (btnQuitBlue.yImage + btnQuitBlue.imageHeight)) {
                    isShowHighScores = false;
                    //System.out.println("yeah 2222");
                }

                if (x > btnReset.xImage
                        && x < (btnReset.xImage + btnReset.imageWidth)
                        && y > btnReset.yImage
                        && y < (btnReset.yImage + btnReset.imageHeight)) {
                    //System.out.println("reset sayang :*");
                }
            } else if (isShowSettings) {
            } else {
                if (x > btnHelp.xImage
                        && x < (btnHelp.xImage + btnHelp.imageWidth)
                        && y > btnHelp.yImage
                        && y < (btnHelp.yImage + btnHelp.imageHeight)) {
                    btnHelp.pointerReleased(x, y);

                    btnHelp.setIsPressed(true);

                    btnAbout.setIsNothing(true);
                    btnAbout.setIsPressed(false);

                    btnSettings.setIsNothing(true);
                    btnSettings.setIsPressed(false);
                    btnHighScores.setIsNothing(true);
                    btnHighScores.setIsPressed(false);

                    btnPlay.setIsNothing(true);
                    btnPlay.setIsPressed(false);
                    btnHelp.setIsPressed(true);

                    keyPressed(-5);
                } else if (x > btnAbout.xImage
                        && x < (btnAbout.xImage + btnAbout.imageWidth)
                        && y > btnAbout.yImage
                        && y < (btnAbout.yImage + btnAbout.imageHeight)) {
                    btnAbout.pointerReleased(x, y);

                    btnAbout.setIsPressed(true);

                    btnPlay.setIsNothing(true);
                    btnPlay.setIsPressed(false);

                    btnSettings.setIsNothing(true);
                    btnSettings.setIsPressed(false);
                    btnHighScores.setIsNothing(true);
                    btnHighScores.setIsPressed(false);

                    btnHelp.setIsNothing(true);
                    btnHelp.setIsPressed(false);
                    keyPressed(-5);
                } else if (x > btnSettings.xImage
                        && x < (btnSettings.xImage + btnSettings.imageWidth)
                        && y > btnSettings.yImage
                        && y < (btnSettings.yImage + btnSettings.imageHeight)) {
                    btnSettings.pointerReleased(x, y);

                    btnSettings.setIsPressed(true);

                    btnPlay.setIsNothing(true);
                    btnPlay.setIsPressed(false);
                    btnAbout.setIsNothing(true);
                    btnAbout.setIsPressed(false);
                    btnHighScores.setIsNothing(true);
                    btnHighScores.setIsPressed(false);
                    btnHelp.setIsNothing(true);
                    btnHelp.setIsPressed(false);
                    keyPressed(-5);
                } else if (x > btnHighScores.xImage
                        && x < (btnHighScores.xImage + btnHighScores.imageWidth)
                        && y > btnHighScores.yImage
                        && y < (btnHighScores.yImage + btnHighScores.imageHeight)) {
                    btnHighScores.pointerReleased(x, y);

                    btnHighScores.setIsPressed(true);

                    btnPlay.setIsNothing(true);
                    btnPlay.setIsPressed(false);
                    btnSettings.setIsNothing(true);
                    btnSettings.setIsPressed(false);
                    btnAbout.setIsNothing(true);
                    btnAbout.setIsPressed(false);
                    btnHelp.setIsNothing(true);
                    btnHelp.setIsPressed(false);
                    keyPressed(-5);
                } else if (x > btnPlay.xImage
                        && x < (btnPlay.xImage + btnPlay.imageWidth)
                        && y > btnPlay.yImage
                        && y < (btnPlay.yImage + btnPlay.imageHeight)) {
                    btnPlay.pointerReleased(x, y);
                    btnPlay.setIsPressed(true);

                    btnAbout.setIsNothing(true);
                    btnAbout.setIsPressed(false);

                    btnSettings.setIsNothing(true);
                    btnSettings.setIsPressed(false);
                    btnHighScores.setIsNothing(true);
                    btnHighScores.setIsPressed(false);

                    btnHelp.setIsNothing(true);
                    btnHelp.setIsPressed(false);

                    keyPressed(-5);
                } else if (x > btnGrass.xImage
                        && x < (btnGrass.xImage + btnGrass.imageWidth)
                        && y > btnGrass.yImage
                        && y < (btnGrass.yImage + btnGrass.imageHeight)) {
                    btnGrass.pointerReleased(x, y);
                    btnGrass.setIsPressed(true);

                    btnDessert.setIsNothing(true);
                    btnDessert.setIsPressed(false);
                    btnSnow.setIsNothing(true);
                    btnSnow.setIsPressed(false);

                    keyPressed(-5);
                } else if (x > btnDessert.xImage
                        && x < (btnDessert.xImage + btnDessert.imageWidth)
                        && y > btnDessert.yImage
                        && y < (btnDessert.yImage + btnDessert.imageHeight)) {
                    btnDessert.pointerReleased(x, y);
                    btnDessert.setIsPressed(true);

                    btnSnow.setIsNothing(true);
                    btnSnow.setIsPressed(false);
                    btnGrass.setIsNothing(true);
                    btnGrass.setIsPressed(false);

                    keyPressed(-5);
                } else if (x > btnSnow.xImage
                        && x < (btnSnow.xImage + btnSnow.imageWidth)
                        && y > btnSnow.yImage
                        && y < (btnSnow.yImage + btnSnow.imageHeight)) {
                    btnSnow.pointerReleased(x, y);
                    btnSnow.setIsPressed(true);

                    btnDessert.setIsNothing(true);
                    btnDessert.setIsPressed(false);
                    btnGrass.setIsNothing(true);
                    btnGrass.setIsPressed(false);

                    keyPressed(-5);
                }
                repaint();
            }
        }

    }

    public void setGeserKiri() {
        isGeserBackKiri = false;
        isGeserKeMenuFromLevel = true;
    }

    public void setHighScores() {
        isShowHighScores = true;
    }

    private String formatNilai(long i) {
        String s = "";
        if (i == 0) {
            s = "----";
        } else if (i < 10) {
            s = "000" + String.valueOf(i);
        } else if (i < 100) {
            s = "00" + String.valueOf(i);
        } else if (i < 1000) {
            s = "0" + String.valueOf(i);
        } else {
            s = String.valueOf(i);
        }
        return s;
    }

    protected void hideNotify() {
        //super.hideNotify();
        //hideNotify();
        paused();
        int xResume = getWidth() / 2 - (imgBtnResume.getWidth() / 2);
        int yResume = getHeight() / 2 - (imgBtnResume.getHeight() / 2);

        btnResume.setPositionXY(xResume, yResume,
                Graphics.TOP | Graphics.LEFT);
    }

    protected void showNotify() {
        //super.showNotify();
        //showNotify();
        if (isPaused) {
            Graphics g = getGraphics();
            drawTransparent(g);
            btnResume.paint(g);
            //checkForKeys();
        }
    }

    private void paused() {
        isPaused = true;
        running = false;
    }
}
